# Maintainer: Alexander Rødseth <rodseth@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: T. Jameson Little <t.jameson.little at gmail dot com>
# Contributor: Usagi Ito <usagi@WonderRabbitProject.net>
# Contributor: siasia <http://pastebin.com/qsBEmNCw>
# Contributor: Julien Nicoulaud <julien.nicoulaud@gmail.com>
# Contributor: Jacob Bang <julemand101gmail.com>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - added source and sha512 for ARMv7h, AArch64 builds of Dart
#  - configure paths and install symlinks for binaries shipped for arm

buildarch=12

pkgname=dart
pkgver=2.12.4
pkgrel=1
pkgdesc='The dart programming language SDK'
arch=('x86_64' 'armv7h' 'aarch64')
url='https://www.dartlang.org/'
depends=('bash')
license=('BSD')
makedepends=('setconf')
options=('!strip')
source_x86_64+=("$pkgname-$pkgver-64.zip::https://storage.googleapis.com/dart-archive/channels/stable/release/$pkgver/sdk/dartsdk-linux-x64-release.zip")
source_armv7h+=("$pkgname-$pkgver-arm.zip::https://storage.googleapis.com/dart-archive/channels/stable/release/$pkgver/sdk/dartsdk-linux-arm-release.zip")
source_aarch64+=("$pkgname-$pkgver-arm64.zip::https://storage.googleapis.com/dart-archive/channels/stable/release/$pkgver/sdk/dartsdk-linux-arm64-release.zip")
sha512sums_x86_64=('f3225a569f6adfd75a02aa59554747149c7a97ea4a69cf4e15fe929e80c05238588602205780155dbb6ae0315a344ee529423a634f46a9d5979895164f62d5bf')
sha512sums_armv7h=('e78ab4e9fa190ac0039b77c7e00726951d3be5cc05a06c4f97d9197427fce43d2a2283f7d64e037e83c21b7d6ffa5fa4d66de9160882ffb1892607bd426f8f71')
sha512sums_aarch64=('cf06976dc1a2c9147c646498b07091a10b83afdc140788a3ff482f570192284b5f114f165ed5db2ad8e7b436966f651409acc2f2c29ae6689ab14d63d5c70eaa')

prepare() {
  # Fix permissions
  find "$pkgname-sdk" -type d -exec chmod a+rx '{}' + \
    -or -type f -exec chmod a+r '{}' +

  cd "$pkgname-sdk/bin"

  # Configure paths
  for _f in dartanalyzer pub dartfmt dartdoc; do
    setconf $_f BIN_DIR "/opt/$pkgname-sdk/bin"
    setconf $_f PROG_NAME "/opt/$pkgname-sdk/bin/$_f"
    setconf $_f SDK_DIR "/opt/$pkgname-sdk/"
  done

  # Extract license (AUTHORS and LICENSE files are missing)
  head -n5 "../include/dart_api.h" > ../../LICENSE
}

package() {
  # Create directories
  install -d "$pkgdir"{"/opt/$pkgname-sdk",/usr/{bin,"share/doc/$pkgname-sdk"}}

  # Package the files
  cp -a "$pkgname-sdk/"* "$pkgdir/opt/$pkgname-sdk/"

  # Set up symbolic links for the executables
  for f in dart dartanalyzer pub dartfmt dartdoc dart2native dartaotruntime; do
    ln -s "/opt/$pkgname-sdk/bin/$f" "$pkgdir/usr/bin/$f"
  done

  # Package samples and documentation
  for f in samples about.html about_files; do
    echo mv "$pkgdir/opt/$pkgname-sdk/$f" "$pkgdir/usr/share/doc/$pkgname/"
  done

  # BSD License
  install -Dm644 LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# vim:set ts=2 sw=2 et:
